const addZero = function (opt) {
  return opt < 10 ? '0' + opt : opt
}
export const time = function (str, opt) {
  let time = new Date(str)
  let year = time.getFullYear()
  let month = addZero(time.getMonth() + 1)
  let date = addZero(time.getDate())
  let hours = addZero(time.getHours())
  let minutes = addZero(time.getMinutes())
  let second = addZero(time.getSeconds())
  let dateArr = [year, month, date, hours, minutes, second]
  if ((typeof opt).toLowerCase() !== 'string') {
    return `${year}/${month}/${date}`
  } else {
    let arr = opt.split('')
    let len = arr.length
    if (len === 1) {
      return year + arr[0] + month + arr[0] + date
    } else if (len === 2) {
      return year + arr[0] + month + arr[0] + date + ' ' + hours + arr[1] + minutes + arr[1] + second
    } else {
      let str = ''
      arr.forEach(function (item, index) {
        if (index === 2) {
          str += dateArr[index] + item + ' '
        } else if (index < len - 1) {
          str += dateArr[index] + item
        } else {
          str += dateArr[index]
        }
      })
      return str
    }
  }
}
export const money = function (opt) {
  let num = opt || 0
  return num.toFixed(2)
}
